import server from '@/config/server'

function post(path, auth = true, config = true) {
  return server.api().post(path).auth(auth).config(config)
}
function get(path, auth = true, config = true) {
  return server.api().get(path).auth(auth).config(config)
}

const api = {
  //案场
  case: {
    clueTargetSettingQuery: post('/dt-bi/clSettingTargets/clueTargetSettingQuery'), //线索、来人达成统计
    exportMultiSheet: post('/dt-bi/clSettingTargets/exportMultiSheet').tag('downloadCenter'), //线索、来人达成导出
    orderTargetSetting: post('/dt-order/bo/building/goal/targetSettingQuery'), //认购、签约、回款目标达成统计
    orderExport: post('/dt-order/bo/building/goal/targetSettingExport').tag('downloadCenter') //认购、签约、回款达成导出
  },
  //公司
  company: {
    paginationQuery: post('/dt-bi/clSettingTargets/paginationQuery'), //线索or来人目标统计查询
    paginationQueryExport: post('/dt-bi/clSettingTargets/paginationQuery/export').tag('downloadCenter'), //线索or来人目标统计导出
    orderList: post('/dt-order/bo/building/goal/targetSettingQueryList'), //认购、签约、回款目标达成列表统计
    orderCount: post('/dt-order/bo/building/goal/targetSettingQueryCount'), //认购、签约、回款目标达成Count数量
    orderExport: post('/dt-order/bo/building/goal/targetSettingQueryExport').tag('downloadCenter') //认购、签约、回款目标达成列表导出
  }
}

function orderCount(params) {
  return api.company.orderCount.fetch(params)
}

function exportSheet(params, fromPage, type) {
  if (fromPage == 'company') {
    if (type == 'CLUETARGET' || type == 'VISITOR') {
      return api.company.paginationQueryExport.fetch(params)
    } else {
      return api.company.orderExport.fetch(params)
    }
  } else {
    if (type == 'CLUETARGET' || type == 'VISITOR') {
      return api.case.exportMultiSheet.fetch(params)
    } else {
      return api.case.orderExport.fetch(params)
    }
  }
}

//查询统计数据
function getTargetSettingQuery(params, fromPage, type) {
  if (fromPage == 'company') {
    if (type == 'CLUETARGET' || type == 'VISITOR') {
      return api.company.paginationQuery.fetch(params)
    } else {
      return api.company.orderList.fetch(params)
    }
  } else {
    if (type == 'CLUETARGET' || type == 'VISITOR') {
      return api.case.clueTargetSettingQuery.fetch(params)
    } else {
      return api.case.orderTargetSetting.fetch(params)
    }
  }
}

function getUnitType(type) {
  let unitType = ''
  switch (type) {
    case 'NUMBER':
      unitType = 1
      break
    case 'AMOUNT':
      unitType = 2
      break
    case 'AREA':
      unitType = 3
      break
    default:
      unitType = ''
      break
  }
  return unitType
}

function getTabsType(tabsType) {
  let type = ''
  switch (tabsType) {
    case 'CLUETARGET':
      type = 1
      break
    case 'VISITOR':
      type = 2
      break
    case 'SUBSCRIPTION':
      type = 3
      break
    case 'CONTRACT':
      type = 4
      break
    case 'PAYMENT':
      type = 5
      break
    default:
      type = ''
      break
  }
  return type
}

export default {
  getTargetSettingQuery,
  exportSheet,
  getTabsType,
  getUnitType,
  orderCount
}
